package com.baoyang.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baoyang.entity.BaoyangUser;
import com.baoyang.entity.ProductName;
import com.baoyang.service.IProductNameService;
import com.baoyang.tool.api.R;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author 金佳军
 * @since 2025-07-08
 */
@RestController
@RequestMapping("/productName")
public class ProductNameController {

    @Resource
    private IProductNameService productNameService;

    /**
     * 添加
     */
    @PostMapping("/add")
    public R add(@RequestBody ProductName productName) {
        return R.status(productNameService.save(productName));
    }

    /**
     * 分页查询
     */
    @GetMapping("pageList")
    public R pageList(@RequestParam(defaultValue = "1") int pageNum,
            @RequestParam(defaultValue = "10") int pageSize,
            @RequestParam(required = false) String name) {
        Page<ProductName> page = new Page<>(pageNum, pageSize);
        IPage<ProductName> productNameIPage = productNameService.pageUserList(page, name);
        return R.data(productNameIPage);
    }

    /**
     * 修改
     */
    @PostMapping("/update")
    public R update(@RequestBody ProductName productName) {
        return R.status(productNameService.updateById(productName));
    }

    /**
     * 删除
     */
    @DeleteMapping("/delete/{id}")
    public R delete(@PathVariable("id") String id) {
        return R.status(productNameService.removeById(id));
    }

    /**
     * 查询所有品名列表
     */
    @GetMapping("/list")
    public R list() {
        return R.data(productNameService.list());
    }

}
